/*
 * Group 3, User Interface Programming II (vt11)
 * Pooya | Flora | Monica | Can
 */
package vical.undo;

import javax.swing.text.JTextComponent;

/**
 * The event for the inserting of text.
 * 
 * @author Can
 */
public class UndoableTextInsertEvent extends UndoableTextEvent {

    public UndoableTextInsertEvent(String newText, JTextComponent textComponent) {
        super("", newText, textComponent);
    }

    public void appendText(String lostText) {
        this.newText += lostText;
    }

    @Override
    public void reexecute() {
        this.textComponent.select(selectionStart, selectionStart);
        this.textComponent.replaceSelection(newText);
    }

    @Override
    public void unexecute() {
        this.textComponent.select(selectionStart, selectionStart + newText.length());
        this.textComponent.replaceSelection("");
    }
}
